package com.acwing.partition20;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/1/11 20:12
 */
public class AC1978奶牛过马路 {

    private static final int N = (int) 1e5 + 10, INF = 0x3f3f3f3f;
    private static int n = 0;
    private static int[][] nums = new int[N][2];
    //前缀最大值和后缀最小值
    private static int[] prefixMax = new int[N], suffixMin = new int[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 1; i <= n; i++) {
            String[] s = reader.readLine().split("\\s+");
            nums[i][0] = Integer.parseInt(s[0]);
            nums[i][1] = Integer.parseInt(s[1]);
        }
        writer.write(resolve() + "\n");
        writer.flush();
    }

    private static int resolve() {
        //排序固定一端，预处理出nums[i][1]的前缀最大值和后缀最小值
        Arrays.sort(nums, 1, n + 1, (o1, o2) -> Integer.compare(o1[0], o2[0]));
        prefixMax[0] = -INF;
        suffixMin[n + 1] = INF;
        for (int i = 1; i <= n; i++) prefixMax[i] = Math.max(prefixMax[i - 1], nums[i][1]);
        for (int i = n; i >= 0; i--) suffixMin[i] = Math.min(suffixMin[i + 1], nums[i][1]);
        int answer = 0;
        //排序后，nums[i]如果满足不会相交的话，就必须满足nums[i][1]大于前缀的最大值prefixMax[i-1]且小于后缀最小值suffixMin[i+1]
        for (int i = 1; i <= n; i++) {
            if (prefixMax[i - 1] < nums[i][1] && nums[i][1] < suffixMin[i + 1]) {
                answer++;
            }
        }
        return answer;
    }
}
